<template>
  <div class="home-page">
    <div class="home-header">
      <img class="avatar" :src="avatar" alt="头像" />
      <div class="user-info">
        <div class="nickname">{{ nickname }}</div>
        <div class="welcome">欢迎使用微信 Web 克隆版</div>
      </div>
    </div>
    <div class="home-nav">
      <button :class="{active: currentTab==='FriendsTab'}" @click="currentTab='FriendsTab'">好友列表</button>
      <button :class="{active: currentTab==='ChatTab'}" @click="currentTab='ChatTab'">聊天</button>
      <button :class="{active: currentTab==='ProfileTab'}" @click="currentTab='ProfileTab'">个人中心</button>
    </div>
    <div class="home-content">
      <component
        :is="currentTab"
        @switchTab="handleSwitchTab"
        ref="friendRequestsTab"
      />
    </div>
    <div class="home-footer">
      <span>© 2024 微信克隆项目</span>
    </div>
  </div>
</template>

<script>
import FriendsTab from './FriendsTab.vue'
import ChatTab from './ChatTab.vue'
import ProfileTab from './ProfileTab.vue'
import FriendRequestsTab from './FriendRequestsTab.vue'

export default {
  name: 'HomePage',
  components: { FriendsTab, ChatTab, ProfileTab, FriendRequestsTab },
  data() {
    return {
      currentTab: 'FriendsTab',
      nickname: localStorage.getItem('nickname') || localStorage.getItem('username') || '微信用户',
      avatar: localStorage.getItem('avatar') || 'https://img.yzcdn.cn/vant/logo.png'
    }
  },
  methods: {
    handleSwitchTab(tabName) {
      this.currentTab = tabName
      // 如果切到好友请求Tab，强制刷新
      if (tabName === 'FriendRequestsTab' && this.$refs.friendRequestsTab) {
        this.$refs.friendRequestsTab.loadRequests()
      }
    }
  }
}
</script>

<style scoped>
.home-page {
  min-height: 100vh;
  background: #e5e6eb;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.home-header {
  display: flex;
  align-items: center;
  margin-top: 40px;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.10);
  padding: 32px 48px;
  min-width: 400px;
  max-width: 90vw;
}
.avatar {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  margin-right: 32px;
  background: #f2f2f2;
  object-fit: cover;
}
.user-info {
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.nickname {
  font-size: 22px;
  font-weight: 700;
  color: #222;
  margin-bottom: 8px;
}
.welcome {
  color: #888;
  font-size: 15px;
}
.home-nav {
  display: flex;
  gap: 28px;
  margin: 32px 0 18px 0;
}
.home-nav button {
  padding: 12px 32px;
  background: #07c160;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  box-shadow: 0 2px 8px rgba(7,193,96,0.08);
}
.home-nav button.active,
.home-nav button:hover {
  background: #13ce66;
}
.home-content {
  width: 600px;
  min-height: 400px;
  background: #fff;
  border-radius: 12px;
  margin: 0 auto 0 auto;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  padding: 24px 32px;
  margin-bottom: 18px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.home-footer {
  margin-top: 10px;
  color: #aaa;
  font-size: 14px;
  text-align: center;
}
@media (max-width: 700px) {
  .home-header, .home-content {
    min-width: unset;
    width: 98vw;
    padding: 18px 4vw 18px 4vw;
  }
  .home-content {
    width: 98vw;
    padding: 12px 2vw;
  }
}
</style>